package com.fruit.util;

import java.util.Collection;
import java.util.Set;

import javax.validation.ConstraintViolation;
import javax.validation.Validation;
import javax.validation.Validator;
import javax.validation.ValidatorFactory;

public class ValidateUtil
{
	public static boolean isValidate(String value)
	{
		if(null!=value&&!"".equals(value.trim()))
		{
			return true;
		}
		return false;
	}
	
	public static boolean isValidate(Object[] arrays)
	{
		if(null!=arrays&&arrays.length>0)
		{
			return true;
		}
		return false;
	}
	
	public static boolean isValidate(Collection<?> collect)
	{
		if(null!=collect&&!collect.isEmpty())
		{
			return true;
		}
		return false;
	}
	public static boolean validateLength(String value,int minLength,int maxLength)
	{
		int len=value.length();
		if(len>=minLength&&len<maxLength)
			return true;
		return false;
	}
	
	public static <T> Set<ConstraintViolation<T>> validate(T t)
	{
		ValidatorFactory factory=Validation.buildDefaultValidatorFactory();
		Validator validator = factory.getValidator(); 
		return validator.validate(t);
	}
}
